home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Program: CShell
- ** File: window2.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1991 Apple Computer, Inc.
- ** All rights reserved.
- */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "CShell.h" /* Get the CShell includes/typedefs, etc. */
- #include "CShellCommon.h" /* Get the stuff in common with rez. */
- #include "CShell.protos" /* Get the prototypes for CShell. */
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TEXTEDITCONTROL__
- #include "TextEditControl.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- extern short gPrintPage; /* Non-zero means we are printing. */
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* This function adds the application's controls to a window. */
-
- #pragma segment Window
- OSErr AppNewWindowControls(FileRecHndl frHndl, WindowPtr window)
- {
- WindowPtr oldPort;
- short i, mode;
- Rect brdrRect, viewRect, destRect;
- TEHandle teHndl, textBox[2];
- Handle text;
- OSErr err;
-
- GetPort(&oldPort);
- SetPort(window);
-
- err = noErr;
- for (i = 0; i < 2; ++i) {
- brdrRect = window->portRect;
- --brdrRect.top;
- --brdrRect.left;
- brdrRect.right -= 14;
- brdrRect.bottom = brdrRect.top + (brdrRect.bottom - brdrRect.top + 1) / 2;
- if (i) {
- brdrRect.top = brdrRect.bottom - 1;
- brdrRect.bottom = window->portRect.bottom + 1;
- }
- viewRect = brdrRect;
- InsetRect(&viewRect, 4, 4);
- destRect = viewRect;
- destRect.right -= 2; /* This fixes a TextEdit problem where the
- ** view has to be a little outside the dest on
- ** the right, or else characters are clipped. */
-
- mode = i ? (cteVScrollAndGrow) : (cteReadOnly + cteVScroll);
- CTENew(rViewCtl, /* View ctl ResID used for TextEdit control. */
- window, /* Window to hold TERecord. */
- &teHndl, /* Return handle for TERecord. */
- &destRect, /* destRect for TERecord */
- &viewRect, /* viewRect for TERecord */
- &brdrRect, /* Used to frame a border. */
- 32000, /* Maximum TextEdit document length. */
- mode /* Read-only or read-write, vert scroll, grow box. */
- );
- if (!(textBox[i] = teHndl)) err = memFullErr;
- }
- (*frHndl)->doc.inBox = textBox[0];
- (*frHndl)->doc.outBox = textBox[1];
-
- if (text = (*frHndl)->doc.textHndl) {
- text = CTESwapText(textBox[1], text, false);
- DisposHandle(text);
- (*frHndl)->doc.textHndl = nil;
- }
-
- SetPort(oldPort);
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Image the document into the current port. */
-
- #pragma segment Window
- void ImageDocument(FileRecHndl frHndl)
- {
- #pragma unused (frHndl)
-
- WindowPtr thePort;
- Rect rct, theInk;
- TEHandle te;
- static short teOffset, teNum;
-
- GetPort(&thePort);
-
- if (!gPrintPage) { /* If not printing... */
- DoDrawGrowIcon(thePort, false, false); /* Draw grow icon without scrollbar lines. */
- DoDrawControls(thePort, false); /* Draw the controls in the window. */
- }
- else {
- if (gPrintPage == 1) teOffset = teNum = 0;
-
- theInk = thePort->portRect;
- InsetRect(&theInk, 4, 4); /* Just so no characters get clipped. */
-
- te = (teNum) ? (*frHndl)->doc.outBox : (*frHndl)->doc.inBox;
- rct = theInk;
- CTEPrint(te, &teOffset, &rct);
- if (teOffset == -1) { /* If TextEdit record is completely printed... */
- teOffset = 0;
- if (teNum) {
- gPrintPage = 0; /* Both TextEdit records are printed. */
- return; /* We are done. */
- }
- ++teNum;
- te = (*frHndl)->doc.outBox;
- if (rct.bottom != theInk.bottom) { /* If space left on the page... */
- rct.top = rct.bottom + 20;
- rct.bottom = theInk.bottom;
- if (rct.top < rct.bottom) {
- CTEPrint(te, &teOffset, &rct);
- if (teOffset == -1) {
- gPrintPage = 0; /* Both TextEdit records are printed. */
- return; /* We are done. */
- }
- }
- }
- }
- }
- }
-
-
-
-